package com.augurit.wf.app.fawen.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.wf.app.fawen.web.form.OaFawenForm;
import com.augurit.wf.common.entity.OaFawen;

public class OaFawenConvertor {
	public static OaFawenForm convertVoToForm(OaFawen entity) {
		if(entity != null) {
			OaFawenForm form = new OaFawenForm();
			form.setId(entity.getId());
			form.setCode(entity.getCode());
			form.setTitle(entity.getTitle());
			form.setKeyWord(entity.getKeyWord());
			form.setSecret(entity.getSecret());
			form.setUrgency(entity.getUrgency());
			form.setMainSend(entity.getMainSend());
			form.setApposeSend(entity.getApposeSend());
			form.setDraftDept(entity.getDraftDept());
			form.setDraftPerson(entity.getDraftPerson());
			form.setCheckStaff(entity.getCheckStaff());
			form.setReviewStaff(entity.getReviewStaff());
			form.setPrintStaff(entity.getPrintStaff());
			form.setCopies(entity.getCopies());
			form.setIssueDate(entity.getIssueDate());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(OaFawenForm form, OaFawen entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getCode() != null && form.getCode().trim().length() > 0)
				entity.setCode(form.getCode().trim());
			if(form.getTitle() != null && form.getTitle().trim().length() > 0)
				entity.setTitle(form.getTitle().trim());
			if(form.getKeyWord() != null && form.getKeyWord().trim().length() > 0)
				entity.setKeyWord(form.getKeyWord().trim());
			if(form.getSecret() != null && form.getSecret().trim().length() > 0)
				entity.setSecret(form.getSecret().trim());
			if(form.getUrgency() != null && form.getUrgency().trim().length() > 0)
				entity.setUrgency(form.getUrgency().trim());
			if(form.getMainSend() != null && form.getMainSend().trim().length() > 0)
				entity.setMainSend(form.getMainSend().trim());
			if(form.getApposeSend() != null && form.getApposeSend().trim().length() > 0)
				entity.setApposeSend(form.getApposeSend().trim());
			if(form.getDraftDept() != null && form.getDraftDept().trim().length() > 0)
				entity.setDraftDept(form.getDraftDept().trim());
			if(form.getDraftPerson() != null && form.getDraftPerson().trim().length() > 0)
				entity.setDraftPerson(form.getDraftPerson().trim());
			if(form.getCheckStaff() != null && form.getCheckStaff().trim().length() > 0)
				entity.setCheckStaff(form.getCheckStaff().trim());
			if(form.getReviewStaff() != null && form.getReviewStaff().trim().length() > 0)
				entity.setReviewStaff(form.getReviewStaff().trim());
			if(form.getPrintStaff() != null && form.getPrintStaff().trim().length() > 0)
				entity.setPrintStaff(form.getPrintStaff().trim());
			entity.setCopies(form.getCopies());
			entity.setIssueDate(form.getIssueDate());
		}
	}
	
	public static List<OaFawenForm> convertVoListToFormList(List<OaFawen> oaFawenList) {
		if(oaFawenList != null && oaFawenList.size() > 0) {
			List<OaFawenForm> oaFawenFormList = new ArrayList();
			for(int i=0; i<oaFawenList.size(); i++) {
				oaFawenFormList.add(convertVoToForm(oaFawenList.get(i)));
			}
			return oaFawenFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<OaFawen> oaFawenList) {
		if(oaFawenList != null && oaFawenList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<oaFawenList.size(); i++) {
				OaFawen entity = oaFawenList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("code", entity.getCode());
				map.put("title", entity.getTitle());
				map.put("keyWord", entity.getKeyWord());
				map.put("secret", entity.getSecret());
				map.put("urgency", entity.getUrgency());
				map.put("mainSend", entity.getMainSend());
				map.put("apposeSend", entity.getApposeSend());
				map.put("draftDept", entity.getDraftDept());
				map.put("draftPerson", entity.getDraftPerson());
				map.put("checkStaff", entity.getCheckStaff());
				map.put("reviewStaff", entity.getReviewStaff());
				map.put("printStaff", entity.getPrintStaff());
				map.put("copies", entity.getCopies() == null ? "" : entity.getCopies().toString());
				map.put("issueDate", DateUtils.dateTimeToString(entity.getIssueDate(), "yyyy-MM-dd"));
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<OaFawen> convertFormListToVoList(List<OaFawenForm> oaFawenFormList) {
		if(oaFawenFormList != null && oaFawenFormList.size() > 0) {
			List<OaFawen> oaFawenList = new ArrayList();
			for(int i=0; i<oaFawenFormList.size(); i++) {
				OaFawen oaFawen = new OaFawen();
				convertFormToVo(oaFawenFormList.get(i), oaFawen);
				oaFawenList.add(oaFawen);
			}
			return oaFawenList;
		}
		return null;
	}
}